package weavingdraft;
import java.awt.GridLayout;

import javax.swing.JPanel;
/**
 *  This class creates the pedal grid that the contestant can interact with. 
 * @author Justin Wong
 *@version 1.0
 */

@SuppressWarnings("serial")
public class PedalGrid extends JPanel{
	/**
	 * The WeavingDraft the object refers to. 
	 */
	private WeavingDraft my_draft;
	/**
	 * The long side of the PedalGrid. 
	 */
	private int long_side;
	/**
	 * The short side length of the PedalGrid. 
	 */
	private int short_side;
	/**
	 * The array of the square panels. 
	 */
	private PedalSquare[] square_panels;
	
	/**
	 * Creates the object of the PedalGrid allowing the contestant to 
	 * interact with it. 
	 * 
	 * @param the_draft the WeavingDraft. 
	 */
	public PedalGrid(WeavingDraft the_draft){
		my_draft = the_draft;
		long_side = my_draft.getLongside();
		short_side = my_draft.getShortside();
		square_panels = new PedalSquare[long_side];
		start();
	}
	/**
	 * Helps determine if a column is selected or not. 
	 * 
	 * @param row int row to inform. 
	 * @return the column number that is selected. 
	 */
	public PedalSquare getSquare(int row){
		return square_panels[row];
	}
	/**
	 * Sets the PedalSquare object to the current row.
	 * 
	 * @param square the square referring to. 
	 * @param row the row to set the square. 
	 */
	public void setSquare(PedalSquare square, int row){
		square_panels[row] = square;
	}
	/**
	 * Creates this JPanel object and sets the layout. 
	 */
	private void start(){
		this.setLayout(new GridLayout(long_side, short_side));
		createSquares();
		this.setVisible(true);
	}
	/**
	 * Creates the squares to this object and JPanel. 
	 */
	private void createSquares(){
		for(int i = 0; i < long_side; i++){
			for(int j = 0; j < short_side; j++){
				PedalSquare square = new PedalSquare(i, j, my_draft, this);
				this.add(square);
			}
		}
	}
}
